const axios = require('axios');

const BASE_URL = 'http://localhost:5000/api';

// 测试所有可能的AI建议动作
const testActions = [
  // 时间相关动作
  'adjust_date',
  'adjust_to_15_30',
  'set_reminder',
  'set_10min_reminder',
  'reschedule_overdue',
  'remind_later',
  
  // 任务状态动作
  'mark_preparing',
  'mark_complete',
  'mark_in_progress',
  
  // 优先级动作
  'elevate_priority',
  'lower_priority',
  'set_priority_p0',
  'set_priority_p1',
  'set_priority_p2',
  'set_priority_p3',
  
  // 通用动作
  'accept',
  'dismiss',
  'snooze',
  'acknowledge',
  'ignore',
  
  // 特殊动作
  'merge_drink_reminders',
  'end_work_today',
  'plan_tomorrow',
  'breakdown_task',
  'auto_schedule',
  
  // 可能从AI生成的动作
  'adjust_time',
  'change_due_date',
  'set_priority',
  'mark_urgent',
  'postpone',
  'advance',
  'optimize_schedule',
  'balance_workload'
];

let authToken = '';
let userId = '';

async function testAllAIActions() {
  console.log('🧪 开始全面测试AI建议动作...\n');
  
  // Step 1: Login to get token
  console.log('🔐 正在登录获取认证token...');
  try {
    const loginResponse = await axios.post(`${BASE_URL}/auth/login/email`, {
      email: 'admin@aide.com',
      password: 'admin123456'
    });

    if (loginResponse.data.success) {
      authToken = loginResponse.data.token;
      userId = loginResponse.data.user.id;
      console.log('✅ 登录成功');
      console.log(`   用户ID: ${userId}`);
      console.log(`   Token: ${authToken.substring(0, 20)}...`);
    } else {
      console.log('❌ 登录失败:', loginResponse.data);
      return;
    }
  } catch (error) {
    console.log('❌ 登录错误:', error.response?.data || error.message);
    return;
  }

  console.log('\n📝 开始测试所有AI建议动作...\n');

  // 测试每个动作
  for (const action of testActions) {
    try {
      console.log(`📝 测试动作: ${action}`);

      const response = await axios.post(`${BASE_URL}/ai/suggestion-feedback`, {
        suggestionId: `test_suggestion_${action}`,
        action: action,
        rating: 5,
        feedbackText: `测试动作: ${action}`
      }, {
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${authToken}`
        }
      });

      if (response.data.success) {
        console.log(`✅ ${action} - 成功`);
        console.log(`   响应: ${JSON.stringify(response.data, null, 2)}`);
      } else {
        console.log(`❌ ${action} - 失败`);
        console.log(`   错误: ${JSON.stringify(response.data, null, 2)}`);
      }

    } catch (error) {
      console.log(`❌ ${action} - 错误`);
      if (error.response) {
        console.log(`   状态码: ${error.response.status}`);
        console.log(`   错误信息: ${JSON.stringify(error.response.data, null, 2)}`);
      } else {
        console.log(`   网络错误: ${error.message}`);
      }
    }

    console.log(''); // 空行分隔
  }

  console.log('🎉 全面测试完成！');
}

// 运行测试
testAllAIActions().catch(console.error);
